/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dumbchat;

import java.util.LinkedHashSet;
import org.pircbotx.Colors;
import org.pircbotx.hooks.*;
import org.pircbotx.hooks.events.*;

/**
 *
 * @author tangd
 */
public class SummonModule extends ListenerAdapter {
    private LinkedHashSet<String> enabledChannels = new LinkedHashSet<String>();
    public SummonModule(String s) {
        enabledChannels.add(s);
    }
    public void onMessage(MessageEvent event) throws Exception {
        if(!enabledChannels.contains(event.getChannel().getName()))
            return;
        String message = event.getMessage().trim();
        if(message.matches("!summon\\s+[^\\s]+")) {
            String target = message.split("\\s+")[1];
            if(event.getChannel().getUsers().contains(event.getBot().getUser(target))) {
                //If the user is in the same channel as the summon
                event.getBot().sendNotice(event.getUser(), Colors.BOLD+"!summon "+Colors.NORMAL+target+" has been PMed");
                event.getBot().sendMessage(event.getBot().getUser(target), Colors.BOLD+"!summon "+Colors.NORMAL+"you have been summoned by "+event.getUser().getNick());
            }
            else {
                event.getBot().sendNotice(event.getUser(), Colors.BOLD+"!summon "+Colors.NORMAL+"user not in channel");
            }
        }
    }
}
